<?php 
session_start();
if (!isset ($_SESSION["id"])) {
	session_destroy();
	echo "<script language='javascript'>top.location.href = 'Login.php';</script>";
	exit;
}

include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$DBsql = new DB_Oracle ();
if(isset($_GET['option'])){
if($_GET['option']=="add"){
	$sql="select count(*) count from sys_permission t where t.permission_name='".$_GET['name']."'";
	$data=$DBsql->fetch_all_array($sql);
	if($data[0]['COUNT']>0){
		echo "<script language='javascript'>alert('没有添加成功您输入的车牌号或者设备编号已经存在');</script>";
		}else{
$sql="insert into sys_permission(permission_index,permission_name)values
(sys_permission_seq.nextval,'".$_GET['name']."')";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('添加成功');</script>";
	else
	echo "<script language='javascript'>alert('没有添加成功');</script>";}
	}
if($_GET['option']=="del"){
	$sql="delete from sys_permission dp where dp.permission_index in (".$_GET['id'].")";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('删除成功');</script>";
	else
	echo "<script language='javascript'>alert('没有删除成功');</script>";
	}
	
if($_GET['option']=="change"){
	$sql="select count(*) count from sys_permission t where t.permission_name='".$_GET['name']."'";
	$data=$DBsql->fetch_all_array($sql);
	if($data[0]['COUNT']>0){
		echo "<script language='javascript'>alert('没有修改成功分组名字已经存在');</script>";
		}else{
$sql="update sys_permission dp
          set dp.permission_index=".$_GET['id'].",
		  dp.permission_name='".$_GET['name']."'
		  where dp.permission_index=".$_GET['id']."";
	if($DBsql->query($sql))
	echo "<script language='javascript'>alert('修改成功');</script>";
	else
	echo "<script language='javascript'>alert('没有修改成功');</script>";}
	
	}}

$sql="select * from sys_permission t";
$rows=$DBsql->fetch_all_array($sql);

$pageSize = 20;
$total=count($rows)== 0 ? 1 : count($rows);
//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
pageft($total, $pageSize, 1, 1, 1, 5);
$displaypg+=$firstcount;
$sql="select *
  	  from (select rownum r,t.permission_index,t.permission_name from sys_permission t) c
	 where c.r > $firstcount
	   and c.r <= $displaypg";
$rows=$DBsql->fetch_all_array($sql);
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/Validform.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script>
<script language='javascript'><!--
function text_value(obj){
	if(obj.value==""){
		obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_wrong Validform_checktip";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="没有输入";		
		}else{obj.parentNode.parentNode.getElementsByTagName("span").item(0).className="Validform_checktip Validform_right";
	obj.parentNode.parentNode.getElementsByTagName("span").item(0).innerHTML="输入正确";}
	}
function ADD(){
     if(document.getElementById('add').value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
	var url="group.php?option=add&name="+document.getElementById('add').value;
	window.location=url;  
		}
function UP(){
           if(document.getElementById("up").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
	var url="group.php?option=change&id="+user_group_id+"&name="+document.getElementById("up").value;
	window.location=url;  
		}
		
		
		
		
function delRow(policechar_id){
if(confirm("确定删除？")){
	var url="group.php?option=del&id="+policechar_id;
	window.location=url; 
	}
	}
	
function delChecked(){
	var chebox=document.getElementsByName('selectID');
	var chebox_value="";
	for(var i=0;i<chebox.length;++i){
		if(chebox.item(i).checked==true){
			chebox_value+=chebox.item(i).value+",";
			}}
    if(chebox_value==""){
		alert("您没有选择东西");
	return 0;
		}
if(confirm("确定删除？")){
	var url="group.php?option=del&id="+chebox_value.substr(0,chebox_value.length-1);
	window.location=url; 
	}	}
	
function CheckAll(obj){var chebox=document.getElementsByName('selectID');if(obj.checked==true){
for(var i=0;i<chebox.length;++i){chebox.item(i).checked=true;}}else{for(var i=0;i<chebox.length;++i){chebox.item(i).checked=false;}}
}

var user_group_id='';
function editRow(rowId){
	user_group_id=rowId;
	var obj=document.getElementById(rowId).getElementsByTagName('td');
		document.getElementById("up").value=obj.item(2).innerHTML;
	POPdiv('UPdiv');	
	}
--></script>
<!--管理列表开始-->
<div class="manageTab">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span><img src="images/001.gif" height="14" width="14" /><a href="javascript:void(null)" onclick="javascript:POPdiv('POPdiv')">新增</a></span><span><img src="images/114.gif" height="14" width="14" /><a onclick="delChecked()" href="javascript:void(null)">批量删除</a></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">用户管理列表</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td>
        <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td class="td90b2">选择</td>
            <td class="td90b2">编号</td>
            <td class="td90b2">用户组名字</td>
            <td class="td90b2">权限分配</td>
            <td class="td90b2">编辑</td>
            <td class="td90b2">删除</td>
          </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
				if($ros['PERMISSION_NAME']=='超级管理员'){
					echo "<tr>
	            <td class=\"tdfff\"><input type='checkbox' name=\"selectID\" class=\"STYLE2\" disabled=\"disabled\"  value=\"".$ros['PERMISSION_INDEX']."\" /></td>
	            <td class=\"tdfff\" style=\"color:#CCC\">".$ros['PERMISSION_INDEX']."</td>
	            <td class=\"tdfff\" style=\"color:#CCC\">".$ros['PERMISSION_NAME']."</td>
	            <td class=\"tdfff\"><img src=\"images/qx.gif\" /> <a href=\"#\" style=\"color:#CCC\">选择权限</a></span></td>
	            <td class=\"tdfff\"><div align=\"center\"><img src=\"images/037.gif\" width=\"9\" height=\"9\" /><span class=\"STYLE1\" style=\"color:#CCC\"> [</span><a href=\"javascript:void(null)\" style=\"color:#CCC\">编辑</a><span style=\"color:#CCC\" class=\"STYLE1\">]</span></div></td>
	            <td class=\"tdfff\"><div align=\"center\"><img src=\"images/010.gif\" width=\"9\" height=\"9\" /><span class=\"STYLE1\" style=\"color:#CCC\"> [</span><a href=\"javascript:void(null)\" style=\"color:#CCC\">删除</a><span class=\"STYLE1\" style=\"color:#CCC\">]</span></div></td>
	          </tr>";
					continue;
					}
          	?>
	          <tr id="<?php echo $ros['PERMISSION_INDEX'];?>">
	            <td class="tdfff"><input type='checkbox' name="selectID" class="STYLE2" value="<?php echo $ros['PERMISSION_INDEX'];?>" /></td>
	            <td class="tdfff"><?php echo $ros['PERMISSION_INDEX'];?></td>
	            <td class="tdfff"><?php echo $ros['PERMISSION_NAME'];?></td>
	            <td class="tdfff"><img src="images/qx.gif" /> <a href="qx.php?id=<?php echo $ros['PERMISSION_INDEX'];?>">选择权限</a></span></td>
	            <td class="tdfff"><div align="center"><img src="images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="editRow('<?php echo $ros['PERMISSION_INDEX'];?>')">编辑</a><span class="STYLE1">]</span></div></td>
	            <td class="tdfff"><div align="center"><img src="images/010.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="delRow('<?php echo $ros['PERMISSION_INDEX'];?>')">删除</a><span class="STYLE1">]</span></div></td>
	          </tr>
          <?php }}else{echo '暂无数据！';}?>
          <tr>
            <td colspan="10" class="tdfff">&nbsp;</td>
          </tr>
        </table>
      </td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
    	 <td height="24" width="8"><img src="images/user_03.gif" height="24" width="8" /></td>
    <td style="background:#3980b2;">
    <div class="green-black"><?php echo $pagenav;?></div>
	</td>
    <td height="24" width="8"><img src="images/user_04.gif" height="24" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->

<!--弹出层新建用户开始-->
      <div id="POPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>增加权限分组</div>
        <div class="POPdiv_content">
			  <table border="0" cellpadding="5" cellspacing="0">
			    <tr>
			      <td width="80"><label for="userNum">分组名字：</label></td>
			      <td><input type="text" id="add" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入分组名称</span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input onclick="ADD()" type="button" class="btnbg" value="添加权限组" style="width:70px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
        </div>
      </div>
<!--弹出层新建用户结束-->


<!--弹出层修改用户开始-->
      <div id="UPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('UPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>修改分组名字</div>
        <div class="POPdiv_content">
			  <table border="0" cellpadding="5" cellspacing="0">
			    <tr>
			      <td width="80"><label for="userNum">分组名字：</label></td>
			      <td><input type="text" id="up" onblur="text_value(this)"/></td>
			      <td><span class="Validform_checktip">请输入分组名称</span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input onclick="UP()" type="button" class="btnbg" value="修改用户组名字" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
        </div>
      </div>
<!--弹出层修改用户结束-->